package dao.Impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import dao.DeleteBookInfoDao;
import entity.BookInfo;
import util.C3P0Util;

public class DeleteBookInfoDaoImpl implements DeleteBookInfoDao{
	//查询sql
	@Override
	public BookInfo selectBookInfo(Integer bookId) {
		BookInfo bookInfo = null;
		//调用C3p0util
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
		//需要执行的查询sql语句
		String sql = "select * from bookinfo where bookId = ?";
		try {
			bookInfo = qr.query(sql, bookId,new BeanHandler<BookInfo>(BookInfo.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bookInfo;
	}
	//删除sql
	@Override
	public Integer deleteBookInfoByBookId(Integer bookId) {
		Integer i = 0;
		
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
		
		String sql = "delete from bookinfo where bookId = ?";
		
		try {
			i = qr.update(sql,bookId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}

}
